<?php
/*
 * Created on 16 sept. 2010
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
class Admin_Model_DbTable_Proprietaire extends Zend_Db_Table
{
	protected $_name = 'proprietaire';
	/**
	 Recupererle point de la muraille par son id
	 */
	public function getProprio($idproprio) {
		$idproprio = (int)$idproprio;
		$row = $this->fetchRow('idproprietaire = ' . $idproprio);
		if (!$row) {
			throw new Exception("Count not find row $idproprio");
		}
		return $row->toArray();    
	}
	
	public function addProprio($longueur,$taille,$terrain,$proprietaire,$origine,$espece,$latitude,$longitude) {
		$data = array(
			'longueur' => $longueur,
			'taille' => $taille,
			'terrain_idterrain' => $terrain,
			'proprietaire_idproprietaire' => $proprietaire,
			'origine_idorigine' => $origine,
			'espece_idespece' => $espece,
			'latitude' => $latitude,
			'longitude' => $longitude,
		);
		$this->insert($data);
	}
	
	public function updateProprio($idarbre, $longueur,$taille,$terrain,$proprietaire,$origine,$espece,$latitude,$longitude) {
		$data = array(
			'longueur' => $longueur,
			'taille' => $taille,
			'terrain_idterrain' => $terrain,
			'proprietaire_idproprietaire' => $proprietaire,
			'origine_idorigine' => $origine,
			'espece_idespece' => $espece,
			'latitude' => $latitude,
			'longitude' => $longitude,
		);
		$this->update($data, 'idarbre = '. (int)$idarbre);
	}
	
	
	public function getProprioMatricegmv($idproprio) {
		
		$idproprio = (int)$idproprio;
        $db = Zend_Db::factory('PDO_MYSQL', array ('host' => '127.0.0.1', 'username'
		 => 'root', 'password' => '@dmin2010gmv', 'dbname'   => 'gmv'));
		$select = $db -> select() -> from('matricegmv')
			-> where('proprietaire_idproprietaire = ? ',$idproprio)
			;
		
		$rows = $select->query()->fetchAll();
		
		$matricegmv = array();
		$matricegmv['total'] = count($rows);
		$matricegmv['rows'] = $rows;
		return $matricegmv;
	}
	public function getProprioMatricebr($idproprio) {
		
		$idproprio = (int)$idproprio;
        $db = Zend_Db::factory('PDO_MYSQL', array ('host' => '127.0.0.1', 'username'
		 => 'root', 'password' => '@dmin2010gmv', 'dbname'   => 'gmv'));
		$select = $db -> select() -> from('matricebr')
			-> where('proprietaire_idproprietaire = ? ',$idproprio)
			;
		
		$rows = $select->query()->fetchAll();
		
		$matricegmv = array();
		$matricegmv['total'] = count($rows);
		$matricegmv['rows'] = $rows;
		return $matricegmv;
	}
	
	function deleteProprio($idarbre) {
		$this->delete ( 'idarbre =' . ( int ) $idarbre );
	}
	/**
	 * 
	 * @return  
	 */
	public function getAllProprio() {    
		$all = $this->fetchAll();
		$arbres = array();
		$arbres['total'] = count($all->toArray());
		$arbres['rows'] = $all->toArray();
		return $arbres ;
	}    
	
}
